home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / getara.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  72 lines

  1. /*****************************************************************************
  2.  
  3.     GetAra()
  4.  
  5.     This function is used by commands which can be preceded by two
  6. arguments which specify an "area" of the edit buffer.  For instance,  the "T"
  7. command can have the form "m,nT",  which will cause the characters between the
  8. mth and nth character of the edit buffer to be typed on the terminal screen.
  9. All commands which support m,n arguments call this function to compute the
  10. addresses of the m and nth characters.  The resulting addresses are left
  11. in the global variables AraBeg and AraEnd.
  12.  
  13. *****************************************************************************/
  14.  
  15. #include "zport.h"        /* define portability identifiers */
  16. #include "tecoc.h"        /* define general identifiers */
  17. #include "defext.h"        /* define external global variables */
  18. #include "deferr.h"        /* define identifiers for error messages */
  19.  
  20. DEFAULT GetAra()        /* get m,n addresses */
  21. {
  22.     LONG    TmpLng;
  23.  
  24. #if DEBUGGING
  25.     static char *DbgFNm = "GetAra";
  26.     sprintf(DbgSBf,"MArgmt = %ld, NArgmt = %ld", MArgmt, NArgmt);
  27.     DbgFEn(4,DbgFNm,DbgSBf);
  28. #endif
  29.  
  30.     if (MArgmt < 0) {            /* if negative m */
  31.         ErrMsg(ERR_NCA);        /* negative argument to , */
  32.         DBGFEX(4,DbgFNm,"FAILURE, negative m");
  33.         return FAILURE;
  34.     }
  35.  
  36.     if (NArgmt < 0)    {            /* if negative n */
  37.         ErrStr(ERR_POP, ErrTxt);    /* POP = pointer off page */
  38.         DBGFEX(4,DbgFNm,"FAILURE, negative n");
  39.         return FAILURE;
  40.     }
  41.  
  42.     if (MArgmt > NArgmt) {            /* if wrong order */
  43.         TmpLng = NArgmt;
  44.         NArgmt = MArgmt;
  45.         MArgmt = TmpLng;
  46.     }
  47.  
  48.     AraBeg = EBfBeg + MArgmt;        /* compute area beginning */
  49.     if (AraBeg > GapBeg-1) {        /* if past start of gap */
  50.         AraBeg += (GapEnd-GapBeg) + 1;    /* correct for gap */
  51.     }
  52.  
  53.     AraEnd = (EBfBeg + NArgmt) - 1;        /* compute area end */
  54.     if (AraEnd > GapBeg-1) {        /* if before end of gap */
  55.         AraEnd += (GapEnd-GapBeg) + 1;    /* correct for gap */
  56.     }
  57.  
  58.     if ((AraBeg > EBfEnd) ||        /* if m or n too large */
  59.         (AraEnd > EBfEnd)) {
  60.         ErrStr(ERR_POP, ErrTxt);    /* POP = pointer off page */
  61.         DBGFEX(4,DbgFNm,"FAILURE");
  62.         return FAILURE;
  63.     }
  64.  
  65. #if DEBUGGING
  66.     sprintf(DbgSBf,"SUCCESS, AraBeg = %ld, AraEnd = %ld",
  67.         Zcp2ul(AraBeg), Zcp2ul(AraEnd));
  68.     DbgFEx(4,DbgFNm,DbgSBf);
  69. #endif
  70.     return SUCCESS;
  71. }
  72.